package org.infinitest;

import static org.infinitest.TestEvent.*;

import java.beans.PropertyChangeEvent;

import junit.framework.AssertionFailedError;

/**
 * Copied from infinitest project
 */
public class EventFakeSupport
{
  private static final Integer SOURCE = new Integer(1);
  public static final String FAILURE_MSG = "Test failed as expected";
  public static final String TEST_NAME = "com.fakeco.TestFoo";
  public static final String TEST_METHOD = "someMethod";

  private EventFakeSupport()
  {
  }

  public static TestEvent withFailingMethod(String methodName)
  {
    return createEvent(methodName, FAILURE_MSG);
  }

  public static PropertyChangeEvent statusFromScanningTo(Status status)
  {
    return new PropertyChangeEvent(SOURCE, ResultCollector.STATUS_PROPERTY, Status.SCANNING, status);
  }

  public static TestEvent withTestNamed(String testName)
  {
    return testCaseStarting(testName);
  }

  public static TestEvent createEvent(String methodName, Throwable error)
  {
    return new TestEvent(TestEvent.TestState.METHOD_ERROR, error.getMessage(), TEST_NAME, methodName, error);
  }

  public static TestEvent createEvent(String methodName, String msg)
  {
    String testMsg = "testFailed(" + msg + ")";
    TestEvent testEvent = new TestEvent(TestEvent.TestState.METHOD_FAILURE, testMsg, TEST_NAME, methodName, new AssertionFailedError());
    return testEvent;
  }

  public static TestEvent eventWithError(Throwable error)
  {
    return new TestEvent(TestEvent.TestState.METHOD_FAILURE, error.getMessage(), TEST_NAME, TEST_METHOD, error);
  }

  public static TestEvent withPassingMethodNamed(String methodName)
  {
    return new TestEvent(TestEvent.TestState.METHOD_SUCCESS, "message", TEST_NAME, methodName, null);
  }

  public static TestEvent withAnyTest()
  {
    return new TestEvent(TestEvent.TestState.TEST_CASE_STARTING, "", TEST_NAME, TEST_METHOD, null);
  }

  public static TestEvent withTest(Class testClass)
  {
    return withTestNamed(testClass.getName());
  }
}
